﻿@model ProductReviewsModel

@using SmartStore.Web.Models.Catalog;
@using SmartStore.Core.Html;

@{
	Html.AddScriptParts("~/Scripts/public.reviews.js");
}

@if (Model.Items.Count == 0)
{
	<p class="text-muted">@T("Reviews.Empty")</p>
}
else
{
	<div class="review-list text-body" id="review-list">
		@for (var i = 0; i < Model.Items.Count; i++)
		{
			var review = Model.Items[i];
			int ratingPercent = review.Rating * 20;
			var helpfulness = review.Helpfulness;

			<div class="review-item" id="review-item-@(i + 1)" itemprop="review" itemscope itemtype="http://schema.org/Review">
				<div class="review-title">
                    <div class="rating" itemprop="reviewRating" itemscope itemtype="https://schema.org/Rating">
                        <div style="width: @(ratingPercent)%"></div>
                        <meta itemprop="ratingValue" content="@review.Rating" />
                    </div>
					<h4 itemprop="name">@review.Title</h4>
				</div>

                <div class="review-meta">
                    <span itemprop="author" itemscope itemtype="https://schema.org/Person">
                        <span class="review-meta-label pr-1">@T("Reviews.From"):</span>
                        @if (review.AllowViewingProfiles)
                        {
                            <a class="review-meta-value" href="@Url.RouteUrl("CustomerProfile", new { id = review.CustomerId })" rel="nofollow" dir="auto" itemprop="name">
                                @(review.CustomerName)
                            </a>
                        }
                        else
                        {
                            <span class="review-meta-value" itemprop="name">@review.CustomerName</span>
                        }
                    </span>

                    <span class="review-meta-label pr-1">@T("Common.Date"):</span>
                    <span class="review-meta-value" itemprop="datePublished" content="@review.WrittenOn.ToString("yyyy-MM-DD")">@review.WrittenOnStr</span>
                </div>

				<p class="review-text" dir="auto" itemprop="reviewBody">
					@Html.Raw(HtmlUtils.SanitizeHtml(review.ReviewText, true))
				</p>

				<div class="review-vote d-flex" data-review-id="@(helpfulness.ProductReviewId)" data-href='@(Url.Action("SetReviewHelpfulness"))'>
					<span class="review-vote-label pr-2">@T("Reviews.Helpfulness.WasHelpful?")</span>
					<a class="review-vote-link review-vote-link-yes mr-1" href="#" title="@T("Common.Yes")" data-toggle="tooltip" rel="nofollow">
						<i class="fa fa-thumbs-up"></i>
						<span class="review-vote-count" data-bind-to="TotalYes"><strong style="font-size:12px">@(helpfulness.HelpfulYesTotal)</strong></span>
					</a>
					<a class="review-vote-link review-vote-link-no mr-1" href="#" title="@T("Common.No")" data-toggle="tooltip" rel="nofollow">
						<i class="fa fa-thumbs-down"></i>
						<span class="review-vote-count" data-bind-to="TotalNo"><strong style="font-size:12px">@(helpfulness.HelpfulNoTotal)</strong></span>
					</a>
				</div>
				
				@{ Html.RenderWidget("productreviews_page_inside_review"); }
			</div>
		}
	</div>

	if (Model.TotalReviewsCount > Model.Items.Count)
	{
		<div class="text-center">
			<a class="btn btn-secondary" href="@Url.Action("Reviews", new { id = Model.ProductId })#review-item-11">
				<span>@T("Reviews.Overview.ReadAll")</span>
			</a>
		</div>
	}
}